home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 68.3 KB | 2,090 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UEditionDocument.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UEDITIONDOCUMENT__
- #include "UEditionDocument.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UDESIGNATOR__
- #include "UDesignator.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __USECTION__
- #include "USection.h"
- #endif
-
- #ifndef __USECTIONMGR__
- #include "USectionMgr.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- const unsigned long kEditionDocRsrcType = 'EdSt';// rsrc type for Edition Doc private rsrc
- const short kEditionDocRsrcID = 301; // rsrc id for Edition Doc private rsrc
- extern const char *kEditionDocRsrcName = "Edition Doc Settings";
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
- typedef struct EditionDocSettings
- { // used for saving settings in a resource
- Boolean showSectionBorders;
- Boolean stopAllEditions;
- } *EditionDocSettingsPtr, ** EditionDocSettingsHandle;
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- //========================================================================================
- // CLASS CSectionIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CObjectIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::CSectionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsLowBound, itsHighBound, itsForward)
-
- {
- } // CSectionIterator::CSectionIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::CSectionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsForward)
- {
- } // CSectionIterator::CSectionIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::CSectionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, kIterateForward)
- {
- } // CSectionIterator::CSectionIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::CSectionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TSectionList* itsSectionList) :
- CObjectIterator(itsSectionList, kIterateForward)
- {
- } // CSectionIterator::CSectionIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::~CSectionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::~CSectionIterator()
- {
- } // CSectionIterator::~CSectionIterator
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::CurrentSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::CurrentSection()
- {
- return (TSection*)this->CurrentObject();
- } // CSectionIterator::CurrentSection
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::FirstSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::FirstSection()
- {
- return (TSection*)this->FirstObject();
- } // CSectionIterator::FirstSection
-
- //----------------------------------------------------------------------------------------
- // CSectionIterator::NextSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::NextSection()
- {
- return (TSection*)this->NextObject();
- } // CSectionIterator::NextSection
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUEditionDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- void InitUEditionDocument()
- {
- FailOSErr(InitEditionPack());
-
- MA_REGISTER_SIGNATURE(TSectionBehavior, kSectionBehavior);
-
- // debug check to ensure that the user has included Editions.r in their <program>.r file
- #if qDebugMsg
- const short kAEEditionsDispatchTable = 401; // ID of our 'aedt' resource
- Handle aedtResource = GetResource('aedt', kAEEditionsDispatchTable);
- if (!aedtResource)
- {
- fprintf(stderr, "###Missing 'aedt' resource id=%d!\n", kAEEditionsDispatchTable);
- ProgramBreak("Did you forget to include Editions.rsrc in your .r file?\n");
- }
- #endif
- } // InitUEditionDocument
-
-
- //========================================================================================
- // CLASS TEditionDocument
- //========================================================================================
- #undef Inherited
- #define Inherited TFileBasedDocument
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TEditionDocument, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TEditionDocument::TEditionDocument()
- {
- fSectionList = NULL;
- fStopAllEditions = FALSE;
- fShowSectionBorders = TRUE;
- fNextEditionNumber = 1;
- fNewPublishers = FALSE;
- fEditionCreator = '\?\?\?\?';
- } // TEditionDocument::TEditionDocument
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::IEditionDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TEditionDocument::IEditionDocument(TFile* itsFile,
- const OSType itsScrapType,
- const OSType editionCreator)
- {
- this->IFileBasedDocument(itsFile, itsScrapType);
-
- fEditionCreator = editionCreator;
-
- FailInfo fi;
- Try(fi)
- {
- TSectionList* aSectionList = new TSectionList;
- aSectionList->ISectionList();
- fSectionList = aSectionList;
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- #if qDebug
- fSectionList->SetEltType("TSection"); // takes MAName
- #endif
-
- InitUSectionMgr(); // ensure it's init'd
- } // TEditionDocument::IEditionDocument
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TEditionDocument::~TEditionDocument()
- {
- fSectionList = (TSectionList *)FreeListIfObject(fSectionList);
- } // TEditionDocument::Free
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::FreeData:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TEditionDocument::FreeData() // override
- {
- fSectionList->FreeAll();
-
- Inherited::FreeData();
- } // TEditionDocument::FreeData
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::CanPublishSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- Boolean TEditionDocument::CanPublishSelection()
- {
- // we can publish if:
- // 1. there is a user selection, and
- // 2. the user selection contains something, and
- // 3. there isn't already a non-canceled publisher EXACTLY contained in the current selection.
-
- TDesignator * userSelection;
- if ((userSelection = this->GetUserSelection()) != NULL)
- {
- if (!userSelection->IsEmpty())
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (!aSection->IsCanceled() && (aSection->GetSectionType() == stPublisher) && userSelection->IsContained(aSection->fDesignator) == kExactlyContained)
- return FALSE;
- }
- else
- return FALSE;
- }
- else
- return FALSE; // if there is no selection, then can't publish the selection
-
- return TRUE;
- } // TEditionDocument::CanPublishSelection
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::CanSubscribe:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- Boolean TEditionDocument::CanSubscribe()
- {
- // we can subscribe if:
- // 1. there is a user selection, and
- // 2. the user selection contains something, and
- // 3. there isn't a non-canceled subscriber currently selected (i.e. don't subscribe OVER a subscriber).
-
- TDesignator * userSelection;
- if ((userSelection = this->GetUserSelection()) != NULL)
- {
- if (!userSelection->IsEmpty())
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (!aSection->IsCanceled() && (aSection->GetSectionType() == stSubscriber) && userSelection->IsContained(aSection->fDesignator) != kNotContained)
- return FALSE;
- }
- else
- return FALSE;
- }
- else
- return FALSE;
-
- return TRUE;
- } // TEditionDocument::CanSubscribe
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoWrite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- void TEditionDocument::DoWrite(TFile* aFile, Boolean makingCopy) // override
- {
- Inherited::DoWrite(aFile, makingCopy);
-
- // 0. warn user if doc has multiple publishers to same edition
- {
- CSectionIterator iter(this);
- TSection* aSection;
- TSection* prevPublisher = NULL;
- for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stPublisher)
- {
- if (prevPublisher)
- {
- if ((*(prevPublisher->fSectionHandle))->controlBlock ==
- (*(aSection->fSectionHandle))->controlBlock)
- {
- this->PoseSavingMultPublishersAlert(prevPublisher);
- break;
- }
- }
- prevPublisher = aSection;
- }
- }
-
- // 1. write out (as a resource) fStopAllEditions and fShowSectionBorders
- this->DoWriteSettings(aFile);
-
- // 2. clear the new publishers flag
- fNewPublishers = FALSE;
-
- // 3. tell each section to write itself out
- {
- CSectionIterator iter(this);
- TSection* aSection;
- for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- aSection->DoWrite(aFile, FALSE);
- }
- } // TEditionDocument::DoWrite
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoWriteSettings:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- void TEditionDocument::DoWriteSettings(TFile*)
- {
- EditionDocSettingsHandle h = (EditionDocSettingsHandle)NewPermHandle(sizeof(EditionDocSettings));
-
- (*h)->showSectionBorders = fShowSectionBorders;
- (*h)->stopAllEditions = fStopAllEditions;
-
- MAAddResource((Handle)h, kEditionDocRsrcType, kEditionDocRsrcID, CStr255(kEditionDocRsrcName));
- FailResError();
- } // TEditionDocument::DoWriteSettings
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoRead:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TEditionDocument::DoRead(TFile* aFile, Boolean forPrinting) // override
- {
- Inherited::DoRead(aFile, forPrinting);
-
- // 1. read in (from a resource) fStopAllEditions and fShowSectionBorders
- this->DoReadSettings(aFile);
-
- // 2. create the section objects and tell each section to read itself in
- for (short i = 1; i <= Count1Resources(rSectionType); ++i)
- {
- short theID;
- Handle h;
-
- h = Get1IndResource(rSectionType, i); // get the resource handle
- FailNILResource((Handle)h);
- theID = (short)(*((SectionHandle)h))->sectionID;
- switch ((*((SectionHandle)h))->kind)
- {
- case stPublisher:
- this->DoReadPublisher(aFile, theID);
- break;
- case stSubscriber:
- this->DoReadSubscriber(aFile, theID);
- break;
- default:
- #if qDebug
- ProgramBreak("SectionHandle appears to be corrupt");
- #endif
- break;
- }
- }
- } // TEditionDocument::DoRead
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoReadSettings:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TEditionDocument::DoReadSettings(TFile*)
- {
- EditionDocSettingsHandle h = (EditionDocSettingsHandle) Get1Resource(kEditionDocRsrcType, kEditionDocRsrcID);
- FailNILResource((Handle)h);
- fShowSectionBorders = (*h)->showSectionBorders;
- fStopAllEditions = (*h)->stopAllEditions;
- ReleaseResource((Handle)h);
- } // TEditionDocument::DoReadSettings
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoReadPublisher:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TEditionDocument::DoReadPublisher(TFile* aFile, short theID)
- {
- TPublisher * aPublisher = this->DoMakePublisher(NULL, NULL, theID);
- FailInfo fi;
- Try(fi)
- {
- aPublisher->DoRead(aFile);
- fi.Success();
- }
- else
- {
- aPublisher = (TPublisher *)(FreeIfObject(aPublisher));
- fi.ReSignal();
- }
- this->AddSection(aPublisher);
- } // TEditionDocument::DoReadPublisher
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoReadSubscriber:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TEditionDocument::DoReadSubscriber(TFile* aFile, short theID)
- {
- TSubscriber * aSubscriber = this->DoMakeSubscriber(NULL, NULL, theID);
- FailInfo fi;
- Try(fi)
- {
- aSubscriber->DoRead(aFile);
- fi.Success();
- }
- else
- {
- aSubscriber = (TSubscriber *)(FreeIfObject(aSubscriber));
- fi.ReSignal();
- }
- this->AddSection(aSubscriber);
- } // TEditionDocument::DoReadSubscriber
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::RevertDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TEditionDocument::RevertDocument()
- {
- this->Abandon();
- Inherited::RevertDocument();
- } // TEditionDocument::RevertDocument
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TEditionDocument::DoMenuCommand(CommandNumber aCommandNumber)// override
-
- {
- switch (aCommandNumber)
- {
- case cCreatePublisher:
- this->DoNewPublisher();
- break;
- case cSubscribeTo:
- {
- TNewSubscriberCommand* aNewSubscriberCommand = new TNewSubscriberCommand;
- aNewSubscriberCommand->INewSubscriberCommand(cSubscribeTo, this);
- this->PostCommand(aNewSubscriberCommand);
- break;
- }
- case cOptions:
- this->DoSectionOptions();
- break;
- case cBorders:
- {
- TSectionBorderCommand * aSectionBorderCmd = new TSectionBorderCommand;
- aSectionBorderCmd->ISectionBorderCommand(cBorders, this);
- this->PostCommand(aSectionBorderCmd);
- break;
- }
- case cStopAllEditions:
- {
- TStopAllEditionsCommand * aStopAllEditionsCmd = new TStopAllEditionsCommand;
- aStopAllEditionsCmd->IStopAllEditionsCommand(cStopAllEditions, this);
- this->PostCommand(aStopAllEditionsCmd);
- break;
- }
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TEditionDocument::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoSectionOptions:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoSectionOptions()
-
- {
- TSection * aSection = this->GetSelectedSection();
- if (aSection)
- {
- if (aSection->GetSectionType() == stPublisher)
- this->DoPublisherOptions((TPublisher *)aSection);
- else if (aSection->GetSectionType() == stSubscriber)
- this->DoSubscriberOptions((TSubscriber *)aSection);
- #if qDebug
- else
- ProgramBreak("what kind of section is it anyway?");
- #endif
- }
- } // TEditionDocument::DoSectionOptions
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TEditionDocument::Close() // override
- {
- short poseResult = cancel;
- long changeCount;
-
- changeCount = this->GetChangeCount();
-
- // preflight the Close for the case in which the document's DATA is unchanged (the change
- // count is 0) but there are new publishers in the document
- if ((changeCount == 0) && fNewPublishers)
- {
- poseResult = this->PoseNewPublishersAlert();
- if (poseResult == cancel)
- Failure(noErr, messageCancelled);
- }
- else if (changeCount && fAskOnClose)
- {
- poseResult = this->PoseSaveDialog();
- if (poseResult == cancel)
- Failure(noErr, messageCancelled);
- }
-
- this->Changed(mClosed,this);
-
- if (poseResult == kYesButton)
- this->SaveDocument(cClose); // Will fail if unable to save
- else if (poseResult == kNoButton)
- this->Abandon();
-
- // Must never be called for a document related to a view in the Clipboard.
- // Why is this???
- CWindowIterator iter(this);
-
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->CloseAndFree();
-
- } // TEditionDocument::Close
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::PoseNewPublishersAlert:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
- short TEditionDocument::PoseNewPublishersAlert()
-
- {
- short returnVal = kNoButton;
-
- FailOSErr(MAInteractWithUser());
-
- CStr255 reason;
- GetIndString(reason, kIDBuzzString, gDispatcher->fDone ? bzQuitting : bzClosing);
- ParamText(fTitle, reason, gEmptyString, gEmptyString);
-
- short oldResFile = MACurResFile();
-
- FailInfo fi;
- Try(fi)
- {
- MAUseResFile(gApplicationRefNum);
- returnVal = MacAppAlert(phNewPublisherAlert, NULL);
- fi.Success();
- }
- else
- {
- MAUseResFile(oldResFile);
- fi.ReSignal();
- }
- MAUseResFile(oldResFile);
-
- return returnVal;
- } // TEditionDocument::PoseNewPublishersAlert
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::PoseMultPublishersAlert:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- short TEditionDocument::PoseMultPublishersAlert(TSection* aSection)
-
- {
- short returnVal = kNoButton;
-
- FailOSErr(MAInteractWithUser());
-
- CStr255 name;
- aSection->GetEditionName(name);
-
- ParamText(name, gEmptyString, gEmptyString, gEmptyString);
- short oldResFile = MACurResFile();
-
- FailInfo fi;
- Try(fi)
- {
- MAUseResFile(gApplicationRefNum);
- returnVal = MacAppAlert(phMultPublisherWrn, NULL);
- fi.Success();
- }
- else
- {
- MAUseResFile(oldResFile);
- fi.ReSignal();
- }
- MAUseResFile(oldResFile);
-
- return returnVal;
- } // TEditionDocument::PoseMultPublishersAlert
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::PoseSavingMultPublishersAlert:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- short TEditionDocument::PoseSavingMultPublishersAlert(TSection* aSection)
-
- {
- short returnVal = kNoButton;
-
- FailOSErr(MAInteractWithUser());
-
- CStr255 name;
- aSection->GetEditionName(name);
- ParamText(name, fTitle, gEmptyString, gEmptyString);
- short oldResFile = MACurResFile();
-
- FailInfo fi;
- Try(fi)
- {
- MAUseResFile(gApplicationRefNum);
- returnVal = MacAppAlert(phSavingMultPublisherWrn, NULL);
- fi.Success();
- }
- else
- {
- MAUseResFile(oldResFile);
- fi.ReSignal();
- }
- MAUseResFile(oldResFile);
-
- return returnVal;
- } // TEditionDocument::PoseSavingMultPublishersAlert
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::Abandon:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TEditionDocument::Abandon() // override
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stPublisher)
- {
- // if publisher is *new* and it hasn't been saved yet,
- // delete the edition container file
- if (((TPublisher*)aSection)->fNewSection)
- ((TPublisher*)aSection)->DeleteEditionFile();
- }
-
- fNewPublishers = FALSE; // no new publishers any more
-
- Inherited::Abandon();
- } // TEditionDocument::Abandon
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoNeedDiskSpace:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- void TEditionDocument::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes)
- {
- Inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
-
- rsrcForkBytes += kRsrcTypeOverhead + kRsrcOverhead +
- sizeof(EditionDocSettings) + strlen(kEditionDocRsrcName) + kLengthByte;
-
- CSectionIterator iter(this);
-
- // if there are any sections to write, add in type overhead for alis', 'sect', and 'DESG'
- if (iter.More())
- rsrcForkBytes += (3 * kRsrcTypeOverhead);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- aSection->DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
-
- } // TEditionDocument::DoNeedDiskSpace
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoAddSectionBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TEditionDocument::DoAddSectionBehavior(TView* itsView)
- // a convenience method supplied for the convenience of the user
- {
- if (itsView)
- {
- TBehavior* itsBehavior = itsView->GetBehaviorWithIdentifier(kSectionBehavior);
- if (!itsBehavior)
- {
- TSectionBehavior* aSectionBehavior = new TSectionBehavior;
- aSectionBehavior->ISectionBehavior(kSectionBehavior);
- itsView->AddBehavior(aSectionBehavior);
- }
- }
- } // TEditionDocument::DoAddSectionBehavior
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoNewPublisher:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoNewPublisher()
-
- {
- OSErr err;
- TDesignator * itsDesignator;
-
- //MAVolatile(NewPublisherReply, reply);
- NewPublisherReply reply; // can't be volatile because it is passed by reference
-
- // set up the reply record
- err = GetLastEditionContainerUsed(&(reply.container));
- if ((err != noErr) && (err != fnfErr)) // allow fnfErr
- FailOSErr(err);
- this->GetNextEditionName(*((CStr63 *) reply.container.theFile.name));
- reply.usePart = FALSE; // always set this to false
-
- // create the preview
- itsDesignator = this->GetUserSelection();
- FailNIL(itsDesignator);
-
- this->DoMakePreview(itsDesignator, reply.previewFormat, reply.preview);
-
- FailInfo fi;
- Try(fi)
- {
- this->DoNewPublisherDialog(reply); // query the user
- fi.Success();
- }
- else
- {
- this->DisposeOfPreview(reply);
- fi.ReSignal();
- }
-
- this->DisposeOfPreview(reply);
-
- if (!reply.canceled)
- {
- FSSpec aFSSpec;
- FSSpecPtr aFSSpecPtr;
-
- if (!reply.replacing)
- FailOSErr(CreateEditionContainerFile(&(reply.container.theFile), this->GetEditionCreatorSignature(), reply.container.theFileScript));
-
- FailInfo fi;
- Try(fi)
- {
- //MAVolatileInit(SectionHandle, sectionH, NULL);
- SectionHandle sectionH = NULL; // can't be volatile because it is passed by reference
- MAVolatileInit(TPublisher*, aPublisher, NULL);
- MAVolatileInit(TDesignator*, newDesignator, NULL);
-
- // Prepare for call to NewSection
- short newSectionID = this->GetUniqueSectRsrcID();
-
- aFSSpecPtr = NULL; // can pass in NULL to NewSection
- TFile* aFile = this->GetFile();
- if (aFile && (aFile->HasValidFileSpec()))
- {
- aFile->GetFileSpec(aFSSpec);
- aFSSpecPtr = &aFSSpec;
- }
-
- // Call NewSection (which calls RegisterSection for us)
- err = NewSection(&(reply.container), aFSSpecPtr, stPublisher, newSectionID, pumOnSave, §ionH);
- if ((err != noErr) && (err != multiplePublisherWrn) && (err != notThePublisherWrn))
- FailOSErr(err);
-
- FailInfo innerfi;
- Try(innerfi)
- {
- // publisher owns its designator -- so clone it
- newDesignator = (TDesignator *)itsDesignator->Clone();
-
- // Create the publisher object, add it to our list of sections,
- // mark it as changed, and publish it to disk.
-
- aPublisher = this->DoMakePublisher(newDesignator, sectionH, newSectionID);
- if ((err == multiplePublisherWrn) || (err == notThePublisherWrn))
- this->PoseMultPublishersAlert(aPublisher);
-
- this->AddSectionAndBorder(aPublisher);
- aPublisher->MarkAsChanged();
- aPublisher->Publish(aFile);
-
- innerfi.Success();
- }
- else // Recover
- {
- if (aPublisher)
- aPublisher = (TPublisher *)(FreeIfObject(aPublisher));
- else
- {
- newDesignator = (TDesignator *)(FreeIfObject(newDesignator));
- if (sectionH && (IsRegisteredSection(sectionH) == noErr))
- UnRegisterSection(sectionH); // Ignore the warnings.
- }
- innerfi.ReSignal();
- }
-
- fi.Success();
- }
- else // Recover
- {
- err = DeleteEditionContainerFile(&(reply.container.theFile));
- fi.ReSignal();
- }
-
- // let the edition document know that there is a new publisher
- fNewPublishers = TRUE;
- }
- } // TEditionDocument::DoNewPublisher
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoMakePreview:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoMakePreview(TDesignator* itsDesignator,
- FormatType& previewFormat,
- Handle& preview)
- {
- MAVolatileInit(Handle&, volatilePreview, preview);
- volatilePreview = NULL;
-
- previewFormat = this->GetPublishPreference();
- if ((previewFormat == 'TEXT') || (previewFormat == 'PICT') || (previewFormat == 'snd '))
- {
- MAVolatileInit(THandleStream*, aHandleStream, NULL);
-
- volatilePreview = NewPermHandle(0);
-
- FailInfo fi;
- Try(fi)
- {
- aHandleStream = new THandleStream;
- aHandleStream->IHandleStream(volatilePreview, 6);
-
- FailInfo innerfi;
- Try(innerfi)
- {
- this->DoWriteData(previewFormat, itsDesignator, aHandleStream);
- innerfi.Success();
- }
- else // Recover
- {
- volatilePreview = DisposeIfHandle(volatilePreview);
- aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
- innerfi.ReSignal();
- }
- aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
- fi.Success();
- }
- else // Recover
- {
- volatilePreview = DisposeIfHandle(volatilePreview);
- fi.ReSignal();
- }
- }
- } // TEditionDocument::DoMakePreview
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DisposeOfPreview:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DisposeOfPreview(NewPublisherReply& reply)
- {
- if (reply.previewFormat == 'PICT')
- reply.preview = (Handle)DisposeIfPicHandle((PicHandle) reply.preview);
- else if (reply.previewFormat == 'TEXT')
- reply.preview = DisposeIfHandle(reply.preview);
- } // TEditionDocument::DisposeOfPreview
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetEditionCreatorSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- OSType TEditionDocument::GetEditionCreatorSignature()
-
- {
- return fEditionCreator;
- } // TEditionDocument::GetEditionCreatorSignature
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetPublishPreference:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- FormatType TEditionDocument::GetPublishPreference()
-
- {
- return ((long)'TEXT'); // by default, prefer to publish 'TEXT'
- // over 'PICT'
- } // TEditionDocument::GetPublishPreference
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoMakePublisher:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- TPublisher* TEditionDocument::DoMakePublisher(TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsSectionID)
- {
- TPublisher * aPublisher = new TPublisher; // create a TPublisher object
- aPublisher->IPublisher(this, itsDesignator, itsSectionHandle, itsSectionID);
- return aPublisher;
- } // TEditionDocument::DoMakePublisher
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoNewPublisherDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoNewPublisherDialog(NewPublisherReply& reply)
-
- {
- // override this method if you decide to use the NewPublisherExpDialog instead
- FailOSErr(MAInteractWithUser());
-
- gClipboardMgr->AboutToLoseControl(TRUE); // so scrap gets converted
- FailOSErr(NewPublisherDialog(&reply));
- gClipboardMgr->RegainControl(TRUE); // so scrap gets converted
- } // TEditionDocument::DoNewPublisherDialog
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoNewSubscriber:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoNewSubscriber()
-
- {
- OSErr err;
- NewSubscriberReply reply;
- short newSectionID;
- FSSpec aFSSpec;
- FSSpecPtr aFSSpecPtr;
- SectionHandle sectionH;
- TSubscriber * aSubscriber;
- TDesignator * aDesignator;
-
- err = GetLastEditionContainerUsed(&(reply.container));// fill in the reply
- if ((err != noErr) && (err != fnfErr)) // allow fnfErr
- FailOSErr(err);
- reply.formatsMask = this->GetSubscriberFormatsMask();// set up the formatsMask
- this->DoNewSubscriberDialog(reply);
- if (!reply.canceled)
- {
- newSectionID = this->GetUniqueSectRsrcID();
- // create a new section handle
- aFSSpecPtr = NULL;
- TFile* aFile = this->GetFile();
- if (aFile && (aFile->HasValidFileSpec()))
- {
- aFile->GetFileSpec(aFSSpec);
- aFSSpecPtr = &aFSSpec;
- }
- FailOSErr(NewSection(&(reply.container), aFSSpecPtr, stSubscriber, newSectionID, sumAutomatic, §ionH));
- // NewSection calls RegisterSection for us
-
- // create a TDesignator for the TSubscriber object
- aDesignator = this->GetUserSelection();
- if (aDesignator)
- aDesignator = (TDesignator *)aDesignator->Clone();// the subscriber owns the designator
-
- // create a TSubscriber object, add it to our list of sections, and mark it as changed
- aSubscriber = this->DoMakeSubscriber(aDesignator, sectionH, newSectionID);
- this->AddSectionAndBorder(aSubscriber);
- aSubscriber->MarkAsChanged();
- }
- } // TEditionDocument::DoNewSubscriber
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoMakeSubscriber:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- TSubscriber* TEditionDocument::DoMakeSubscriber(TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsSectionID)
- {
- // create and return a TSubscriber object
- TSubscriber * aSubscriber = new TSubscriber;
- aSubscriber->ISubscriber(this, itsDesignator, itsSectionHandle, itsSectionID);
- return aSubscriber;
- } // TEditionDocument::DoMakeSubscriber
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoNewSubscriberDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoNewSubscriberDialog(NewSubscriberReply& reply)
-
- {
- // override this method if you decide to use the NewSubscriberExpDialog instead
- FailOSErr(MAInteractWithUser());
-
- gClipboardMgr->AboutToLoseControl(TRUE); // so scrap gets converted
- FailOSErr(NewSubscriberDialog(&reply)); // pose the new subscriber dialog
- gClipboardMgr->RegainControl(TRUE); // so scrap gets converted
- } // TEditionDocument::DoNewSubscriberDialog
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoPublisherOptions:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoPublisherOptions(TPublisher* aPublisher)
-
- {
- SectionOptionsReply reply;
-
- reply.sectionH = aPublisher->fSectionHandle;
- this->DoPublisherOptionsDialog(reply);
- if (!reply.canceled)
- {
- if (reply.changed)
- aPublisher->MarkAsChanged();
-
- if (reply.action == sectionWriteMsgID)
- {
- TFile* aFile = this->GetFile();
- aPublisher->Publish(aFile);
- }
- else if (reply.action == sectionCancelMsgID)
- {
- TSectionCancelEventCommand * aSectionCancelEventCommand = new TSectionCancelEventCommand;
- aSectionCancelEventCommand->ISectionCancelEventCommand(cCancelPublisher, this, aPublisher);
- this->PostCommand(aSectionCancelEventCommand);
- }
- }
- } // TEditionDocument::DoPublisherOptions
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoPublisherOptionsDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoPublisherOptionsDialog(SectionOptionsReply& reply)
-
- {
- // override this method if you decide to use the SectionOptionsExpDialog instead
- FailOSErr(MAInteractWithUser());
-
- gClipboardMgr->AboutToLoseControl(TRUE); // so scrap gets converted
- FailOSErr(SectionOptionsDialog(&reply));
- gClipboardMgr->RegainControl(TRUE); // so scrap gets converted
- } // TEditionDocument::DoPublisherOptionsDialog
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoSubscriberOptions:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoSubscriberOptions(TSubscriber* aSubscriber)
-
- {
- SectionOptionsReply reply;
-
- reply.sectionH = aSubscriber->fSectionHandle;
- this->DoSubscriberOptionsDialog(reply);
- if (!reply.canceled)
- {
- if (reply.changed)
- aSubscriber->MarkAsChanged();
-
- if (reply.action == sectionReadMsgID)
- aSubscriber->Subscribe();
- else if (reply.action == 'goto')
- aSubscriber->OpenPublisher();
- else if (reply.action == sectionCancelMsgID)
- {
- TSectionCancelEventCommand * aSectionCancelEventCommand = new TSectionCancelEventCommand;
- aSectionCancelEventCommand->ISectionCancelEventCommand(cCancelSubscriber, this, aSubscriber);
- this->PostCommand(aSectionCancelEventCommand);
- }
- }
- } // TEditionDocument::DoSubscriberOptions
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoSubscriberOptionsDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoSubscriberOptionsDialog(SectionOptionsReply& reply)
-
- {
- // override this method if you decide to use the SectionOptionsExpDialog instead
- FailOSErr(MAInteractWithUser());
-
- gClipboardMgr->AboutToLoseControl(TRUE); // so scrap gets converted
- FailOSErr(SectionOptionsDialog(&reply));
- gClipboardMgr->RegainControl(TRUE); // so scrap gets converted
- } // TEditionDocument::DoSubscriberOptionsDialog
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TEditionDocument::DoSetupMenus() // override
-
- {
- Inherited::DoSetupMenus();
-
- if (fNewPublishers) // there are new publishers!
- {
- Enable(cSave, TRUE);
- Enable(cRevert, TRUE);
- }
-
- Enable(cCreatePublisher, this->CanPublishSelection());
- Enable(cSubscribeTo, this->CanSubscribe());
-
- TSection * aSection = this->GetSelectedSection();
- if (aSection)
- {
- Enable(cOptions, TRUE);
- if (aSection->GetSectionType() == stPublisher)
- SetIndividualCommandName(cOptions, kIDBuzzString, bzPublisherOptions);
- else if (aSection->GetSectionType() == stSubscriber)
- SetIndividualCommandName(cOptions, kIDBuzzString, bzSubscriberOptions);
- #if qDebug
- else
- ProgramBreak("what kind of section is it anyway?");
- #endif
- }
-
- Enable(cBorders, TRUE);
- SetMenuState(cBorders, kIDBuzzString, bzShowBorders, bzHideBorders, fShowSectionBorders);
-
- EnableCheck(cStopAllEditions, TRUE, fStopAllEditions);
- } // TEditionDocument::DoSetupMenus
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetNextEditionName:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::GetNextEditionName(CStr63& editionName)
-
- {
- CStr255 name;
- GetIndString(name, kIDBuzzString, bzUntitled);
-
- short preInsert;
- short constChars;
- if (ParseTitleTemplate(name, preInsert, constChars))
- {
- CStr255 numStr;
- NumToString(fNextEditionNumber, numStr);
- if (SubstituteInTitle(name, numStr, preInsert, constChars))
- ++fNextEditionNumber;
- }
-
- editionName = name;
- } // TEditionDocument::GetNextEditionName
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetSubscriberFormatsMask:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- SignedByte TEditionDocument::GetSubscriberFormatsMask()
-
- {
- // Return a mask corresponding to the edition format type to display within the
- // subscriber dialog box. This mask may consist of as many types as are supported in
- // the application. Construct the mask as follows:
- // GetSubscriberFormatsMask = [kPICTformatMask] [+] [kTextformatMask [+] [ksndFormatMask]
-
- if (this->GetPublishPreference() == 'TEXT')
- return (kTEXTformatMask);
- else if (this->GetPublishPreference() == 'PICT')
- return (kPICTformatMask);
- else if (this->GetPublishPreference() == 'snd ')
- return (ksndFormatMask);
-
- return 0;
- } // TEditionDocument::GetSubscriberFormatsMask
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetUniqueSectRsrcID:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- const short kFirstRsrcID = 1000;
- const short kLastRsrcID = 32767;
- const short kBitsInArray = kLastRsrcID - kFirstRsrcID;
-
- short TEditionDocument::GetUniqueSectRsrcID()
- {
- short counter = 0;
- Size arraySize = (kBitsInArray / sizeof(Byte)) + 1;
- Ptr aPtr = NewPermPtr(arraySize);
- Boolean foundNewID;
-
- BlockSet(aPtr, arraySize, 0x00); // zero it out
-
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- {
- short itsRsrcID = aSection->fRsrcID;
-
- if (itsRsrcID >= kFirstRsrcID)
- BitSet(aPtr, itsRsrcID - kFirstRsrcID);
- else
- {
- #if qDebug
- ProgramBreak("problem with section rsrc id");
- #endif
- }
- }
-
- while (BitTst(aPtr, counter) && (counter < kBitsInArray))
- ++counter;
-
- foundNewID =!BitTst(aPtr, counter); // see if we got a new rsrc id
-
- aPtr = DisposeIfPtr(aPtr); // dispose of the array
-
- if (!foundNewID)
- Failure(minErr, 0);
-
- return (counter + kFirstRsrcID); // return the new sect rsrc id
- } // TEditionDocument::GetUniqueSectRsrcID
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoPostMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TEditionDocument::DoPostMakeViews(Boolean forPrinting)
- {
- // The case that we're concerned with here is the TApplication::OpenOld case, in which
- // our DoRead method will get called before there are any views. This method provides
- // a way for borders to be added to views "after the fact" to handle the OpenOld case.
- // The document will have been read in (DoRead), the views created (DoMakeViews) and
- // finally the post create method called (DoPostMakeViews) at which point the borders
- // can then be safely added.
-
- if (!forPrinting)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- this->DoAddBorder(aSection);
- }
-
- Inherited::DoPostMakeViews(forPrinting);
- } // TEditionDocument::DoPostMakeViews
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoAddBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoAddBorder(TSection* /* aSection */)
-
- {
- // subclasses should override this to create a border to adorn this section
- } // TEditionDocument::DoAddBorder
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoAdjustBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoAdjustBorder(TSection* /* aSection */)
-
- {
- // subclasses should override this to create a border to adorn this section
- } // TEditionDocument::DoAdjustBorder
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::DoDeleteBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::DoDeleteBorder(TSection* /* aSection */)
-
- {
- // subclasses should override this to remove the border adorning this section
- } // TEditionDocument::DoDeleteBorder
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::IsBorderShown:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- Boolean TEditionDocument::IsBorderShown(TSection* aSection)
-
- {
- if (!aSection->IsCanceled())
- return (fShowSectionBorders || (this->GetSelectedSection() == aSection));
- else
- return FALSE;
- } // TEditionDocument::IsBorderShown
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::IsSectionSelected:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- Boolean TEditionDocument::IsSectionSelected(TSection* aSection)
- // !!! should really be called TEditionDocument::IsSectionInSelection
- {
- if (aSection && !aSection->IsCanceled() && aSection->fDesignator)
- {
- TDesignator* userSelection = this->GetUserSelection();
- if (userSelection)
- return (userSelection->IsContained(aSection->fDesignator) != kNotContained);
- else
- return (FALSE);
- }
- else
- return (FALSE);
- } // TEditionDocument::IsSectionSelected
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::AddSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::AddSection(TSection* aSection)
-
- {
- // Protect against double installation
- if (fSectionList)
- {
- if (fSectionList->GetIdentityItemNo(aSection) == 0)// doesn't already exist in list
- fSectionList->Insert(aSection);
- }
- #if qDebug
- else
- ProgramBreak("fSectionList is NULL");
- #endif
-
- // add the section to the section mgr's list of registered sections
- TSectionMgr* aSectionMgr =
- (TSectionMgr*) gDispatcher->GetBehaviorWithIdentifier(kSectionMgrBehaviorID);
- if (aSectionMgr)
- aSectionMgr->fSectionList->Insert(aSection);
- } // TEditionDocument::AddSection
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::AddSectionAndBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::AddSectionAndBorder(TSection* aSection)
-
- {
- this->AddSection(aSection);
- // notify the document to create a border for this section
- this->DoAddBorder(aSection);
- } // TEditionDocument::AddSectionAndBorder
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::RemoveSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::RemoveSection(TSection* aSection)
-
- {
- if (fSectionList)
- fSectionList->Delete(aSection);
- #if qDebug
- else
- ProgramBreak("fSectionList is NULL");
- #endif
-
- // add the section to the section mgr's list of registered sections
- TSectionMgr* aSectionMgr =
- (TSectionMgr*) gDispatcher->GetBehaviorWithIdentifier(kSectionMgrBehaviorID);
- if (aSectionMgr)
- aSectionMgr->fSectionList->Delete(aSection);
- } // TEditionDocument::RemoveSection
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::CancelSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::CancelSection(TSection* aSection, Boolean cancel)
- {
- aSection->CancelSection(cancel);
-
- // notify the document to add or delete a border for this section
- if (cancel)
- this->DoDeleteBorder(aSection);
- else
- this->DoAddBorder(aSection);
- } // TEditionDocument::CancelSection
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::GetSelectedSection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- TSection* TEditionDocument::GetSelectedSection()
- {
- TSection* selectedSection = NULL;
-
- CSectionIterator iter(this);
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (this->IsSectionSelected(aSection))
- if (!selectedSection)
- selectedSection = aSection;
- else
- { // in this case, >1 sections are in the user selection, so need to
- // determine which section is the preferred selected section
- if (aSection->fDesignator->GetSize() < selectedSection->fDesignator->GetSize())
- selectedSection = aSection;
- }
-
- return selectedSection;
- } // TEditionDocument::GetSelectedSection
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::SetSectionBorders:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::SetSectionBorders(Boolean state, Boolean invalidate)
- {
- if (fShowSectionBorders != state)
- {
- fShowSectionBorders = state;
-
- if (invalidate)
- {
- CWindowIterator iter(this);
-
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->ForceRedraw();
- }
- }
- // This could be a lot smarter if we had a reference to the view that had the borders.
- // Something like the following could be done instead:
- // CAdornerIterator iter(fViewWithBorders);
- // for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- // if ((anAdorner->fIdentifier == kPublisherAdornerID)
- // || (anAdorner->fIdentifier == kSubscriberAdornerID))
- // anAdorner->InvalidateAdorner(fCellsView);
- } // TEditionDocument::SetSectionBorders
-
- //----------------------------------------------------------------------------------------
- // TEditionDocument::SetStopAllEditions:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TEditionDocument::SetStopAllEditions(Boolean state)
- {
- if (fStopAllEditions != state)
- {
- fStopAllEditions = state;
- if (!state) // if turning "off" stop editions
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stSubscriber)
- ((TSubscriber*)aSection)->SubscribeIfNewer();
- }
- }
- } // TEditionDocument::SetStopAllEditions
-
-
- //========================================================================================
- // CLASS TNewSubscriberCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TNewSubscriberCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TNewSubscriberCommand::TNewSubscriberCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TNewSubscriberCommand::TNewSubscriberCommand()
- {
- } // TNewSubscriberCommand::TNewSubscriberCommand
-
- //----------------------------------------------------------------------------------------
- // TNewSubscriberCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TNewSubscriberCommand::~TNewSubscriberCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TNewSubscriberCommand::INewSubscriberCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TNewSubscriberCommand::INewSubscriberCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
- {
- this->ICommand(itsCommandNumber, itsDocument, kCantUndo, kCausesChange, itsDocument);
- } // TNewSubscriberCommand::INewSubscriberCommand
-
- //----------------------------------------------------------------------------------------
- // TNewSubscriberCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TNewSubscriberCommand::DoIt()
- {
- ((TEditionDocument*)fContext)->DoNewSubscriber();
- } // TNewSubscriberCommand::DoIt
-
-
- //========================================================================================
- // CLASS TSectionBorderCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TSectionBorderCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionBorderCommand::TSectionBorderCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionBorderCommand::TSectionBorderCommand()
- {
- } // TSectionBorderCommand::TSectionBorderCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionBorderCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionBorderCommand::~TSectionBorderCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionBorderCommand::ISectionBorderCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TSectionBorderCommand::ISectionBorderCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
- {
- this->ICommand(itsCommandNumber, itsDocument->GetContext(itsCommandNumber), kCanUndo, kCausesChange, itsDocument);
-
- fShowSectionBorders =!((TEditionDocument *)itsDocument)->fShowSectionBorders;
- } // TSectionBorderCommand::ISectionBorderCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionBorderCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionBorderCommand::DoIt()
-
- {
- ((TEditionDocument *)fContext)->SetSectionBorders(fShowSectionBorders, kInvalidate);
- } // TSectionBorderCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TSectionBorderCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TSectionBorderCommand::UndoIt()
-
- {
- ((TEditionDocument *)fContext)->SetSectionBorders(!fShowSectionBorders, kInvalidate);
- } // TSectionBorderCommand::UndoIt
-
-
- //========================================================================================
- // CLASS TStopAllEditionsCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TStopAllEditionsCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TStopAllEditionsCommand::TStopAllEditionsCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TStopAllEditionsCommand::TStopAllEditionsCommand()
- {
- } // TStopAllEditionsCommand::TStopAllEditionsCommand
-
- //----------------------------------------------------------------------------------------
- // TStopAllEditionsCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TStopAllEditionsCommand::~TStopAllEditionsCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TStopAllEditionsCommand::IStopAllEditionsCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TStopAllEditionsCommand::IStopAllEditionsCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
-
- {
- this->ICommand(itsCommandNumber, itsDocument->GetContext(itsCommandNumber), kCanUndo, kCausesChange, itsDocument);
-
- fStopAllEditions =!((TEditionDocument *)itsDocument)->fStopAllEditions;
- } // TStopAllEditionsCommand::IStopAllEditionsCommand
-
- //----------------------------------------------------------------------------------------
- // TStopAllEditionsCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TStopAllEditionsCommand::DoIt()
-
- {
- ((TEditionDocument *)fContext)->SetStopAllEditions(fStopAllEditions);
- } // TStopAllEditionsCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TStopAllEditionsCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TStopAllEditionsCommand::UndoIt()
-
- {
- ((TEditionDocument *)fContext)->SetStopAllEditions(!fStopAllEditions);
- } // TStopAllEditionsCommand::UndoIt
-
-
- //========================================================================================
- // CLASS TSectionAdorner
- //========================================================================================
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TSectionAdorner, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionAdorner constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- TSectionAdorner::TSectionAdorner()
- {
- fSection = NULL;
- fBorderRegion = NULL;
- } // TSectionAdorner::TSectionAdorner
-
- //----------------------------------------------------------------------------------------
- // TSectionAdorner::ISectionAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- void TSectionAdorner::ISectionAdorner(IDType itsID,
- TSection* itsSection,
- RgnHandle itsBorderRegion)
- {
- this->IAdorner(itsID,kFreeOnDeletion);
-
- fSection = itsSection;
- fBorderRegion = itsBorderRegion;
- } // TSectionAdorner::ISectionAdorner
-
- //----------------------------------------------------------------------------------------
- // TSectionAdorner::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- TSectionAdorner::~TSectionAdorner()
-
- {
- fBorderRegion = DisposeIfRgnHandle(fBorderRegion);
- } // TSectionAdorner::Free
-
- //----------------------------------------------------------------------------------------
- // TSectionAdorner::InvalidateAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- void TSectionAdorner::InvalidateAdorner(TView* itsView) // override
-
- {
- if (itsView && fBorderRegion)
- itsView->InvalidateRegion(fBorderRegion);
- } // TSectionAdorner::InvalidateAdorner
-
- //----------------------------------------------------------------------------------------
- // TSectionAdorner::DrawBorder:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerRes
-
- void TSectionAdorner::DrawBorder(const Pattern& whichPattern)
-
- {
- PenNormal();
- PenMode(patXor);
- PenSize(3, 3);
- PenPat(&whichPattern);
-
- // Don't use FillRgn since it ignores the penMode.
- FrameRgn(fBorderRegion);
- } // TSectionAdorner::DrawBorder
-
-
- //========================================================================================
- // CLASS TSubscriberAdorner
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionAdorner
-
- #pragma segment MAAdornerNonRes
- MA_DEFINE_CLASS_M1(TSubscriberAdorner, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSubscriberAdorner::TSubscriberAdorner: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSubscriberAdorner::TSubscriberAdorner()
- {
- } // TSubscriberAdorner::TSubscriberAdorner
-
- //----------------------------------------------------------------------------------------
- // TSubscriberAdorner destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSubscriberAdorner::~TSubscriberAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSubscriberAdorner::ISubscriberAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- void TSubscriberAdorner::ISubscriberAdorner(IDType itsID,
- TSubscriber* itsSubscriber,
- RgnHandle itsBorderRegion)
- {
- this->ISectionAdorner(itsID, itsSubscriber, itsBorderRegion);
- } // TSubscriberAdorner::ISubscriberAdorner
-
- //----------------------------------------------------------------------------------------
- // TSubscriberAdorner::DoHighlightSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerRes
-
- void TSubscriberAdorner::DoHighlightSelection(TView* itsView,
- const VRect& ,
- HLState fromHL,
- HLState toHL) // override
- {
- if (itsView)
- {
- TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
- if ((itsDocument) && (itsDocument->IsBorderShown(fSection)))
- if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
- this->DrawBorder(qd.dkGray); // turning off
- else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
- this->DrawBorder(qd.dkGray); // turning on
- }
- } // TSubscriberAdorner::DoHighlightSelection
-
-
- //========================================================================================
- // CLASS TPublisherAdorner
- //========================================================================================
- #undef Inherited
- #define Inherited TSectionAdorner
-
- #pragma segment MAAdornerNonRes
- MA_DEFINE_CLASS_M1(TPublisherAdorner, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPublisherAdorner::TPublisherAdorner: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TPublisherAdorner::TPublisherAdorner()
- {
- } // TPublisherAdorner::TPublisherAdorner
-
- //----------------------------------------------------------------------------------------
- // TPublisherAdorner destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TPublisherAdorner::~TPublisherAdorner()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPublisherAdorner::IPublisherAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerNonRes
-
- void TPublisherAdorner::IPublisherAdorner(IDType itsID,
- TPublisher* itsPublisher,
- RgnHandle itsBorderRegion)
- {
- this->ISectionAdorner(itsID, itsPublisher, itsBorderRegion);
- } // TPublisherAdorner::IPublisherAdorner
-
- //----------------------------------------------------------------------------------------
- // TPublisherAdorner::DoHighlightSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAAdornerRes
-
- void TPublisherAdorner::DoHighlightSelection(TView* itsView,
- const VRect& ,
- HLState fromHL,
- HLState toHL) // override
- {
- if (itsView)
- {
- TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
- if ((itsDocument) && (itsDocument->IsBorderShown(fSection)))
- if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
- this->DrawBorder(qd.gray); // turning off
- else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
- this->DrawBorder(qd.gray); // turning on
- }
- } // TPublisherAdorner::DoHighlightSelection
-
-
- //========================================================================================
- // CLASS TSectionBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TSectionBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSectionBehavior::TSectionBehavior: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TSectionBehavior::TSectionBehavior()
- {
- } // TSectionBehavior::TSectionBehavior
-
- //----------------------------------------------------------------------------------------
- // TSectionBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSectionBehavior::~TSectionBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSectionBehavior::ISectionBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TSectionBehavior::ISectionBehavior(IDType itsIdentifier)
- {
- this->IBehavior(itsIdentifier);
- } // TSectionBehavior::ISectionBehavior
-
- //----------------------------------------------------------------------------------------
- // TSectionBehavior::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TSectionBehavior::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- TView* itsView = (TView*) fOwner;
- // itsView->Focus();
- CPoint qdMouse = itsView->ViewToQDPt(theMouse);
-
- CAdornerIterator iter(itsView);
-
- for (TAdorner* theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
- {
- if ((theAdorner->fIdentifier == kPublisherAdornerID)
- || (theAdorner->fIdentifier == kSubscriberAdornerID))
- {
- TEditionDocument* itsEditionDocument = (TEditionDocument*) itsView->fDocument;
- TSectionAdorner* itsSectionAdorner = (TSectionAdorner*)theAdorner;
- TSection* itsSection = itsSectionAdorner->fSection;
- if ((event->fClickCount == 1) && (PtInRgn(qdMouse, itsSectionAdorner->fBorderRegion)))
- {
- TDesignator* theSelection = itsSection->fDesignator;
- if (theSelection)
- {
- if ((theSelection = (TDesignator*) theSelection->Clone()) != NULL)
- ((TView*) fOwner)->SetUserSelection(theSelection);
- }
- return TRUE;
- }
- else if ((event->fClickCount > 1) && (PtInRgn(qdMouse, itsSectionAdorner->fBorderRegion)))
- {
- if (itsSection->GetSectionType() == stPublisher)
- itsEditionDocument->DoPublisherOptions((TPublisher *) itsSection);
- else
- {
- if (event->IsOptionKeyPressed())
- ((TSubscriber*)itsSection)->OpenPublisher();
- else
- itsEditionDocument->DoSubscriberOptions((TSubscriber*)itsSection);
- }
- return TRUE;
- }
- }
- }
-
- return Inherited::DoMouseCommand(theMouse, event, hysteresis);
- } // TSectionBehavior::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TSectionBehavior::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TSectionBehavior::GetStandardSignature()
- {
- return kSectionBehavior;
- } // TSectionBehavior::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // End of UEditionDocument.cp
-
- #pragma segment Inline
-